import api from './config'

// 评论相关API接口
export const commentApi = {
  // 发表评论
  addComment: (resourceId, data) => {
    return api.post(`/resources/${resourceId}/comments`, data)
  },

  // 更新评论
  updateComment: (commentId, data) => {
    return api.put(`/comments/${commentId}`, data)
  },

  // 删除评论
  deleteComment: (commentId) => {
    return api.delete(`/comments/${commentId}`)
  },

  // 获取资源的评论列表
  getResourceComments: (resourceId, params = {}) => {
    return api.get(`/resources/${resourceId}/comments`, { params })
  },

  // 获取用户的评论列表
  getUserComments: (params = {}) => {
    return api.get('/comments', { params })
  },

  // 根据ID获取评论
  getCommentById: (commentId) => {
    return api.get(`/comments/${commentId}`)
  },

  // 获取最新评论
  getLatestComments: (limit = 10) => {
    return api.get('/comments/latest', { params: { limit } })
  },

  // 获取资源评论数量
  getResourceCommentCount: (resourceId) => {
    return api.get(`/resources/${resourceId}/comments/count`)
  },

  // 获取用户评论数量
  getUserCommentCount: () => {
    return api.get('/comments/count')
  },

  // 管理员获取所有评论
  getAllComments: (params = {}) => {
    return api.get('/admin/comments', { params })
  },

  // 管理员批量删除评论
  batchDeleteComments: (commentIds) => {
    return api.delete('/admin/comments/batch', { data: { commentIds } })
  }
}

export default commentApi 